package cn.mw.cmdb.util;

import cn.mw.cmdb.enums.DateTypeEnum;
import cn.mw.microMonitorCommon.util.DateUtils;
import com.google.common.base.Strings;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class BaseUtil {
    private final static String maxTime = " 23:59:59";
    public static Date getNowLocalTime() {
//        LocalDateTime nowTime = LocalDateTime.now();
//        ZoneOffset offset = ZoneOffset.UTC;
//        Instant instant = nowTime.toInstant(offset);
//        Date date = Date.from(instant);
        Date date = new Date();
        return date;
    }

    public static List<Long> getTimeIntervalByType(String startDateStr, String endDateStr, int typeCode) {
        List<Long> timeList = new ArrayList<>();
        Long startTime = DateUtils.addHours(new Date(), -1).getTime() / 1000;
        Long endTime = new Date().getTime() / 1000;
        DateTypeEnum dateTypeEnum = DateTypeEnum.getDateTypeEnum(typeCode);
        switch (dateTypeEnum) {//1：hour 2:day 3:week 4:month
            case hours:
                startTime = DateUtils.addHours(new Date(), -1).getTime() / 1000;
                break;
            case twelveHours:
                startTime = DateUtils.addHours(new Date(), -12).getTime() / 1000;
                break;
            case days:
                startTime = DateUtils.addDays(new Date(), -1).getTime() / 1000;
                break;
            case weeks:
                startTime = DateUtils.addWeeks(new Date(), -1).getTime() / 1000;
                break;
            case months:
                startTime = DateUtils.addMonths(new Date(), -1).getTime() / 1000;
                break;
            case custom:
                if (!Strings.isNullOrEmpty(startDateStr)) {
                    startTime = DateUtils.parse(startDateStr).getTime() / 1000;
                }
                if (!Strings.isNullOrEmpty(endDateStr+ maxTime)) {
                    endTime = DateUtils.parse(endDateStr+ maxTime).getTime() / 1000;
                }
                break;
            default:
                break;
        }
        timeList.add(startTime);
        timeList.add(endTime);
        return timeList;
    }


}
